package com.b2b.util;

import com.b2b.model.MasterOrderDto;
import com.b2b.model.MasterOrderGoodsDto;
import com.b2b.model.entity.MasterOrder;
import com.b2b.model.entity.MasterOrderGoods;
import com.b2b.service.MasterOrderGoodsService;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.persistence.Column;
import java.util.Date;

@Component
public class MasterOrderUtil {
    private final MasterOrderGoodsService masterOrderGoodsService;
    private final CompanyInfoUtil companyInfoUtil;
    @Autowired
    public MasterOrderUtil(MasterOrderGoodsService masterOrderGoodsService,CompanyInfoUtil companyInfoUtil){
        this.masterOrderGoodsService = masterOrderGoodsService;
        this.companyInfoUtil = companyInfoUtil;
    }

    public MasterOrder getMasterOrder(MasterOrderDto masterOrderDto){
        MasterOrder masterOrder = new MasterOrder();
        masterOrder.setMasterOrderId(masterOrderDto.getMasterOrderId());
        masterOrder.setMasterOrderTime(masterOrderDto.getMasterOrderTime());
        masterOrder.setTransactionValidity(masterOrderDto.getTransactionValidity());
        masterOrder.setRemarks(masterOrderDto.getRemarks());
        masterOrder.setExchangeAgreement(masterOrderDto.getExchangeAgreement());
        masterOrder.setExchangeRate(masterOrderDto.getExchangeRate());
        masterOrder.setDeliveryAgreement(masterOrderDto.getDeliveryAgreement());
        masterOrder.setBuyerState(masterOrderDto.getBuyerState());
        masterOrder.setSellerState(masterOrderDto.getSellerState());
        masterOrder.setOrderState(masterOrderDto.getOrderState());
        masterOrder.setContractFilePath(masterOrderDto.getContractFilePath());
        masterOrder.setBuyerId(masterOrderDto.getBuyerId());
        masterOrder.setSellerId(masterOrderDto.getSellerId());

        return masterOrder;
    }

    public MasterOrderDto getMasterOrderDto(MasterOrder masterOrder){
        MasterOrderDto masterOrderDto = new MasterOrderDto();
        masterOrderDto.setMasterOrderId(masterOrder.getMasterOrderId());
        masterOrderDto.setMasterOrderTime(masterOrder.getMasterOrderTime());
        masterOrderDto.setTransactionValidity(masterOrder.getTransactionValidity());
        masterOrderDto.setRemarks(masterOrder.getRemarks());
        masterOrderDto.setExchangeAgreement(masterOrder.getExchangeAgreement());
        masterOrderDto.setExchangeRate(masterOrder.getExchangeRate());
        masterOrderDto.setDeliveryAgreement(masterOrder.getDeliveryAgreement());
        masterOrderDto.setBuyerState(masterOrder.getBuyerState());
        masterOrderDto.setSellerState(masterOrder.getSellerState());
        masterOrderDto.setOrderState(masterOrder.getOrderState());
        masterOrderDto.setContractFilePath(masterOrder.getContractFilePath());
        masterOrderDto.setBuyerId(masterOrder.getBuyerId());
        masterOrderDto.setSellerId(masterOrder.getSellerId());
        masterOrderDto.setSellerName(companyInfoUtil.getCompanyName(masterOrder.getSellerId()));

        return masterOrderDto;
    }
    public MasterOrderGoods getMasterOrderGoods(MasterOrderGoodsDto masterOrderGoodsDto){
        MasterOrderGoods masterOrderGoods = new MasterOrderGoods();
        masterOrderGoods.setMasterOrderId(masterOrderGoodsDto.getMasterOrderId());
        masterOrderGoods.setFloor(masterOrderGoodsDto.getFloor());
        masterOrderGoods.setNumber(masterOrderGoodsDto.getNumber());
        masterOrderGoods.setPrice(masterOrderGoodsDto.getPrice());
        masterOrderGoods.setCompletedNumber(masterOrderGoodsDto.getCompletedNumber());
        masterOrderGoods.setTopLimit(masterOrderGoodsDto.getTopLimit());
        masterOrderGoods.setStockId(masterOrderGoodsDto.getStockId());

        return masterOrderGoods;
    }
}
